(* 树是对称的：左子树和右子树互为镜像,只比较结构,忽略了节点的值 *)

type 'a binary_tree =
  | Empty
  | Node of 'a * 'a binary_tree * 'a binary_tree   (* 当前节点 ，当前左子树，当前右子树 *)

let rec is_mirror t1 t2 =
  match t1, t2 with
  | Empty, Empty -> true
  | Node(_, l1, r1), Node(_, l2, r2) ->
     is_mirror l1 r2 && is_mirror r1 l2
  | _ -> false

let is_symmetric = function
  | Empty -> true
  | Node(_, l, r) -> is_mirror l r
;;

(* is_symmetric(construct [5;3;18;1;4;12;21]);;
not (is_symmetric (construct [3; 2; 5; 7; 4]));; *)

